package logic

import (
	"context"
	"fmt"
	"luck/model/cache"

	"luck/luckrpc/internal/svc"
	"luck/luckrpc/luckrpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type RemoveCartLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewRemoveCartLogic(ctx context.Context, svcCtx *svc.ServiceContext) *RemoveCartLogic {
	return &RemoveCartLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *RemoveCartLogic) RemoveCart(in *luckrpc.RemoveCartRequest) (*luckrpc.RemoveCartResponse, error) {
	// todo: add your logic here and delete this line
	err := cache.RemoveCart(in.UserId, in.ProductId)
	if err != nil {
		return nil, fmt.Errorf("移除购物车失败")
	}
	return &luckrpc.RemoveCartResponse{}, nil
}
